home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / src / tev.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  23KB  |  1,300 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: tev.c,v 1.4 1997/06/27 17:32:58 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33.  
  34. /*
  35.  *    tev.c
  36.  *
  37.  *    Tracing routines.
  38.  *
  39.  */
  40.  
  41.  
  42. #include <stdio.h>
  43. #include <pvm3.h>
  44. #ifdef WIN32
  45. #include "..\xdr\types.h"
  46. #include "..\xdr\xdr.h"
  47. #else
  48. #include <rpc/types.h>
  49. #include <rpc/xdr.h>
  50. #endif
  51. #include "pmsg.h"
  52. #include "tvdefs.h"
  53. #include "lpvm.h"
  54. #include <pvmtev.h>
  55. #include "tevmac.h"
  56. #include "global.h"
  57.  
  58.  
  59. /***************
  60.  **  Globals  **
  61.  **           **
  62.  ***************/
  63.  
  64. struct pmsg *midtobuf();
  65.  
  66.  
  67. /***************
  68.  **  Private  **
  69.  **           **
  70.  ***************/
  71.  
  72.  
  73. /* "High Performance" Direct Packing Guts Macros :-) */
  74.  
  75. #define PACK_BYTE( _vp, _cnt, _std ) \
  76.     (pvmtrcmp->m_codef->enc_byte) \
  77.         ( pvmtrcmp, (void *) _vp, _cnt, _std, 1 )
  78.  
  79. #define PACK_CPLX( _vp, _cnt, _std ) \
  80.     (pvmtrcmp->m_codef->enc_cplx) \
  81.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(float) * 2 )
  82.  
  83. #define PACK_DCPLX( _vp, _cnt, _std ) \
  84.     (pvmtrcmp->m_codef->enc_dcplx) \
  85.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(double) * 2 )
  86.  
  87. #define PACK_DOUBLE( _vp, _cnt, _std ) \
  88.     (pvmtrcmp->m_codef->enc_double) \
  89.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(double) )
  90.  
  91. #define PACK_FLOAT( _vp, _cnt, _std ) \
  92.     (pvmtrcmp->m_codef->enc_float) \
  93.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(float) )
  94.  
  95. #define PACK_INT( _vp, _cnt, _std ) \
  96.     (pvmtrcmp->m_codef->enc_int) \
  97.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(int) )
  98.  
  99. #define PACK_UINT( _vp, _cnt, _std ) \
  100.     (pvmtrcmp->m_codef->enc_int) \
  101.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(int) )
  102.  
  103. #define PACK_LONG( _vp, _cnt, _std ) \
  104.     (pvmtrcmp->m_codef->enc_long) \
  105.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(long) )
  106.  
  107. #define PACK_ULONG( _vp, _cnt, _std ) \
  108.     (pvmtrcmp->m_codef->enc_long) \
  109.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(long) )
  110.  
  111. #define PACK_SHORT( _vp, _cnt, _std ) \
  112.     (pvmtrcmp->m_codef->enc_short) \
  113.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(short) )
  114.  
  115. #define PACK_USHORT( _vp, _cnt, _std ) \
  116.     (pvmtrcmp->m_codef->enc_short) \
  117.         ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(short) )
  118.  
  119. #define PACK_STRING( _vp ) \
  120.     ( pvmtrctmp = strlen( _vp ) + 1, \
  121.         (pvmtrcmp->m_codef->enc_int) \
  122.             ( pvmtrcmp, (void *) &pvmtrctmp, 1, 1, sizeof(int) ), \
  123.         (pvmtrcmp->m_codef->enc_byte) \
  124.             ( pvmtrcmp, (void *) _vp, pvmtrctmp, 1, 1 ) )
  125.  
  126.  
  127. /* Trace Event Data Packing Routines - Descriptor */
  128.  
  129. static int
  130. tev_pack_byte_desc( did, array, datap, cnt, std )
  131. int did;
  132. int array;
  133. void *datap;
  134. int cnt;
  135. int std;
  136. {
  137.     int type;
  138.     int cc;
  139.  
  140.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  141.         return( cc );
  142.  
  143.     type = TEV_DATA_BYTE | array;
  144.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  145.         return( cc );
  146.  
  147.     if ( array == TEV_DATA_ARRAY )
  148.     {
  149.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  150.             return( cc );
  151.     }
  152.  
  153.     return( PACK_BYTE( datap, cnt, std ) );
  154. }
  155.  
  156. static int
  157. tev_pack_cplx_desc( did, array, datap, cnt, std )
  158. int did;
  159. int array;
  160. void *datap;
  161. int cnt;
  162. int std;
  163. {
  164.     int type;
  165.     int cc;
  166.  
  167.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  168.         return( cc );
  169.  
  170.     type = TEV_DATA_CPLX | array;
  171.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  172.         return( cc );
  173.  
  174.     if ( array == TEV_DATA_ARRAY )
  175.     {
  176.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  177.             return( cc );
  178.     }
  179.  
  180.     return( PACK_CPLX( datap, cnt, std ) );
  181. }
  182.  
  183. static int
  184. tev_pack_dcplx_desc( did, array, datap, cnt, std )
  185. int did;
  186. int array;
  187. void *datap;
  188. int cnt;
  189. int std;
  190. {
  191.     int type;
  192.     int cc;
  193.  
  194.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  195.         return( cc );
  196.  
  197.     type = TEV_DATA_DCPLX | array;
  198.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  199.         return( cc );
  200.  
  201.     if ( array == TEV_DATA_ARRAY )
  202.     {
  203.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  204.             return( cc );
  205.     }
  206.  
  207.     return( PACK_DCPLX( datap, cnt, std ) );
  208. }
  209.  
  210. static int
  211. tev_pack_double_desc( did, array, datap, cnt, std )
  212. int did;
  213. int array;
  214. void *datap;
  215. int cnt;
  216. int std;
  217. {
  218.     int type;
  219.     int cc;
  220.  
  221.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  222.         return( cc );
  223.  
  224.     type = TEV_DATA_DOUBLE | array;
  225.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  226.         return( cc );
  227.  
  228.     if ( array == TEV_DATA_ARRAY )
  229.     {
  230.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  231.             return( cc );
  232.     }
  233.  
  234.     return( PACK_DOUBLE( datap, cnt, std ) );
  235. }
  236.  
  237. static int
  238. tev_pack_float_desc( did, array, datap, cnt, std )
  239. int did;
  240. int array;
  241. void *datap;
  242. int cnt;
  243. int std;
  244. {
  245.     int type;
  246.     int cc;
  247.  
  248.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  249.         return( cc );
  250.  
  251.     type = TEV_DATA_FLOAT | array;
  252.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  253.         return( cc );
  254.  
  255.     if ( array == TEV_DATA_ARRAY )
  256.     {
  257.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  258.             return( cc );
  259.     }
  260.  
  261.     return( PACK_FLOAT( datap, cnt, std ) );
  262. }
  263.  
  264. static int
  265. tev_pack_int_desc( did, array, datap, cnt, std )
  266. int did;
  267. int array;
  268. void *datap;
  269. int cnt;
  270. int std;
  271. {
  272.     int type;
  273.     int cc;
  274.  
  275.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  276.         return( cc );
  277.  
  278.     type = TEV_DATA_INT | array;
  279.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  280.         return( cc );
  281.  
  282.     if ( array == TEV_DATA_ARRAY )
  283.     {
  284.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  285.             return( cc );
  286.     }
  287.  
  288.     return( PACK_INT( datap, cnt, std ) );
  289. }
  290.  
  291. static int
  292. tev_pack_uint_desc( did, array, datap, cnt, std )
  293. int did;
  294. int array;
  295. void *datap;
  296. int cnt;
  297. int std;
  298. {
  299.     int type;
  300.     int cc;
  301.  
  302.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  303.         return( cc );
  304.  
  305.     type = TEV_DATA_UINT | array;
  306.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  307.         return( cc );
  308.  
  309.     if ( array == TEV_DATA_ARRAY )
  310.     {
  311.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  312.             return( cc );
  313.     }
  314.  
  315.     return( PACK_UINT( datap, cnt, std ) );
  316. }
  317.  
  318. static int
  319. tev_pack_long_desc( did, array, datap, cnt, std )
  320. int did;
  321. int array;
  322. void *datap;
  323. int cnt;
  324. int std;
  325. {
  326.     int type;
  327.     int cc;
  328.  
  329.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  330.         return( cc );
  331.  
  332.     type = TEV_DATA_LONG | array;
  333.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  334.         return( cc );
  335.  
  336.     if ( array == TEV_DATA_ARRAY )
  337.     {
  338.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  339.             return( cc );
  340.     }
  341.  
  342.     return( PACK_LONG( datap, cnt, std ) );
  343. }
  344.  
  345. static int
  346. tev_pack_ulong_desc( did, array, datap, cnt, std )
  347. int did;
  348. int array;
  349. void *datap;
  350. int cnt;
  351. int std;
  352. {
  353.     int type;
  354.     int cc;
  355.  
  356.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  357.         return( cc );
  358.  
  359.     type = TEV_DATA_ULONG | array;
  360.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  361.         return( cc );
  362.  
  363.     if ( array == TEV_DATA_ARRAY )
  364.     {
  365.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  366.             return( cc );
  367.     }
  368.  
  369.     return( PACK_ULONG( datap, cnt, std ) );
  370. }
  371.  
  372. static int
  373. tev_pack_short_desc( did, array, datap, cnt, std )
  374. int did;
  375. int array;
  376. void *datap;
  377. int cnt;
  378. int std;
  379. {
  380.     int type;
  381.     int cc;
  382.  
  383.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  384.         return( cc );
  385.  
  386.     type = TEV_DATA_SHORT | array;
  387.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  388.         return( cc );
  389.  
  390.     if ( array == TEV_DATA_ARRAY )
  391.     {
  392.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  393.             return( cc );
  394.     }
  395.  
  396.     return( PACK_SHORT( datap, cnt, std ) );
  397. }
  398.  
  399. static int
  400. tev_pack_ushort_desc( did, array, datap, cnt, std )
  401. int did;
  402. int array;
  403. void *datap;
  404. int cnt;
  405. int std;
  406. {
  407.     int type;
  408.     int cc;
  409.  
  410.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  411.         return( cc );
  412.  
  413.     type = TEV_DATA_USHORT | array;
  414.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  415.         return( cc );
  416.  
  417.     if ( array == TEV_DATA_ARRAY )
  418.     {
  419.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  420.             return( cc );
  421.     }
  422.  
  423.     return( PACK_USHORT( datap, cnt, std ) );
  424. }
  425.  
  426. static int
  427. tev_pack_string_desc( did, array, datap, cnt, std )
  428. int did;
  429. int array;
  430. void *datap;
  431. int cnt;
  432. int std;
  433. {
  434.     int type;
  435.     int num;
  436.     int cc;
  437.     int i;
  438.  
  439.     if ( (cc = PACK_INT( &did, 1, 1 )) )
  440.         return( cc );
  441.  
  442.     type = TEV_DATA_STRING | array;
  443.     if ( (cc = PACK_INT( &type, 1, 1 )) )
  444.         return( cc );
  445.  
  446.     if ( array == TEV_DATA_ARRAY )
  447.     {
  448.         if ( std <= 0 )
  449.             return( PvmBadParam );
  450.  
  451.         num = ( cnt + ( std - 1 ) ) / std;
  452.         if ( (cc = PACK_INT( &num, 1, 1 )) )
  453.             return( cc );
  454.  
  455.         for ( i=0 ; i < cnt ; i += std )
  456.             if ( (cc = PACK_STRING( ((char **) datap)[i] )) )
  457.                 return( cc );
  458.  
  459.         return( 0 );
  460.     }
  461.  
  462.     else
  463.         return( PACK_STRING( (char *) datap ) );
  464. }
  465.  
  466.  
  467. /* Trace Event Data Packing Routines - Raw */
  468.  
  469. static int
  470. tev_pack_byte_raw( did, array, datap, cnt, std )
  471. int did;
  472. int array;
  473. void *datap;
  474. int cnt;
  475. int std;
  476. {
  477.     int cc;
  478.  
  479.     if ( array == TEV_DATA_ARRAY )
  480.     {
  481.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  482.             return( cc );
  483.     }
  484.  
  485.     return( PACK_BYTE( datap, cnt, std ) );
  486. }
  487.  
  488. static int
  489. tev_pack_cplx_raw( did, array, datap, cnt, std )
  490. int did;
  491. int array;
  492. void *datap;
  493. int cnt;
  494. int std;
  495. {
  496.     int cc;
  497.  
  498.     if ( array == TEV_DATA_ARRAY )
  499.     {
  500.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  501.             return( cc );
  502.     }
  503.  
  504.     return( PACK_CPLX( datap, cnt, std ) );
  505. }
  506.  
  507. static int
  508. tev_pack_dcplx_raw( did, array, datap, cnt, std )
  509. int did;
  510. int array;
  511. void *datap;
  512. int cnt;
  513. int std;
  514. {
  515.     int cc;
  516.  
  517.     if ( array == TEV_DATA_ARRAY )
  518.     {
  519.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  520.             return( cc );
  521.     }
  522.  
  523.     return( PACK_DCPLX( datap, cnt, std ) );
  524. }
  525.  
  526. static int
  527. tev_pack_double_raw( did, array, datap, cnt, std )
  528. int did;
  529. int array;
  530. void *datap;
  531. int cnt;
  532. int std;
  533. {
  534.     int cc;
  535.  
  536.     if ( array == TEV_DATA_ARRAY )
  537.     {
  538.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  539.             return( cc );
  540.     }
  541.  
  542.     return( PACK_DOUBLE( datap, cnt, std ) );
  543. }
  544.  
  545. static int
  546. tev_pack_float_raw( did, array, datap, cnt, std )
  547. int did;
  548. int array;
  549. void *datap;
  550. int cnt;
  551. int std;
  552. {
  553.     int cc;
  554.  
  555.     if ( array == TEV_DATA_ARRAY )
  556.     {
  557.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  558.             return( cc );
  559.     }
  560.  
  561.     return( PACK_FLOAT( datap, cnt, std ) );
  562. }
  563.  
  564. static int
  565. tev_pack_int_raw( did, array, datap, cnt, std )
  566. int did;
  567. int array;
  568. void *datap;
  569. int cnt;
  570. int std;
  571. {
  572.     int cc;
  573.  
  574.     if ( array == TEV_DATA_ARRAY )
  575.     {
  576.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  577.             return( cc );
  578.     }
  579.  
  580.     return( PACK_INT( datap, cnt, std ) );
  581. }
  582.  
  583. static int
  584. tev_pack_uint_raw( did, array, datap, cnt, std )
  585. int did;
  586. int array;
  587. void *datap;
  588. int cnt;
  589. int std;
  590. {
  591.     int cc;
  592.  
  593.     if ( array == TEV_DATA_ARRAY )
  594.     {
  595.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  596.             return( cc );
  597.     }
  598.  
  599.     return( PACK_UINT( datap, cnt, std ) );
  600. }
  601.  
  602. static int
  603. tev_pack_long_raw( did, array, datap, cnt, std )
  604. int did;
  605. int array;
  606. void *datap;
  607. int cnt;
  608. int std;
  609. {
  610.     int cc;
  611.  
  612.     if ( array == TEV_DATA_ARRAY )
  613.     {
  614.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  615.             return( cc );
  616.     }
  617.  
  618.     return( PACK_LONG( datap, cnt, std ) );
  619. }
  620.  
  621. static int
  622. tev_pack_ulong_raw( did, array, datap, cnt, std )
  623. int did;
  624. int array;
  625. void *datap;
  626. int cnt;
  627. int std;
  628. {
  629.     int cc;
  630.  
  631.     if ( array == TEV_DATA_ARRAY )
  632.     {
  633.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  634.             return( cc );
  635.     }
  636.  
  637.     return( PACK_ULONG( datap, cnt, std ) );
  638. }
  639.  
  640. static int
  641. tev_pack_short_raw( did, array, datap, cnt, std )
  642. int did;
  643. int array;
  644. void *datap;
  645. int cnt;
  646. int std;
  647. {
  648.     int cc;
  649.  
  650.     if ( array == TEV_DATA_ARRAY )
  651.     {
  652.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  653.             return( cc );
  654.     }
  655.  
  656.     return( PACK_SHORT( datap, cnt, std ) );
  657. }
  658.  
  659. static int
  660. tev_pack_ushort_raw( did, array, datap, cnt, std )
  661. int did;
  662. int array;
  663. void *datap;
  664. int cnt;
  665. int std;
  666. {
  667.     int cc;
  668.  
  669.     if ( array == TEV_DATA_ARRAY )
  670.     {
  671.         if ( (cc = PACK_INT( &cnt, 1, 1 )) )
  672.             return( cc );
  673.     }
  674.  
  675.     return( PACK_USHORT( datap, cnt, std ) );
  676. }
  677.  
  678. static int
  679. tev_pack_string_raw( did, array, datap, cnt, std )
  680. int did;
  681. int array;
  682. void *datap;
  683. int cnt;
  684. int std;
  685. {
  686.     int num;
  687.     int cc;
  688.     int i;
  689.  
  690.     if ( array == TEV_DATA_ARRAY )
  691.     {
  692.         if ( std <= 0 )
  693.             return( PvmBadParam );
  694.  
  695.         num = ( cnt + ( std - 1 ) ) / std;
  696.         if ( (cc = PACK_INT( &num, 1, 1 )) )
  697.             return( cc );
  698.  
  699.         for ( i=0 ; i < cnt ; i += std )
  700.             if ( (cc = PACK_STRING( ((char **) datap)[i] )) )
  701.                 return( cc );
  702.  
  703.         return( 0 );
  704.     }
  705.  
  706.     else
  707.         return( PACK_STRING( (char *) datap ) );
  708. }
  709.  
  710.  
  711. /* ARGSUSED */
  712. static int
  713. tev_pack_nop( did, array, datap, cnt, std )
  714. int did;
  715. int array;
  716. void *datap;
  717. int cnt;
  718. int std;
  719. {
  720.     return( 0 );
  721. }
  722.  
  723.  
  724. /* Trace Descriptor Packing Vector */
  725.  
  726. static struct pvmtrcencvec pvmtrccodef_desc = {
  727.     tev_pack_byte_desc,
  728.     tev_pack_cplx_desc,
  729.     tev_pack_dcplx_desc,
  730.     tev_pack_double_desc,
  731.     tev_pack_float_desc,
  732.     tev_pack_int_desc,
  733.     tev_pack_uint_desc,
  734.     tev_pack_long_desc,
  735.     tev_pack_ulong_desc,
  736.     tev_pack_short_desc,
  737.     tev_pack_ushort_desc,
  738.     tev_pack_string_desc };
  739.  
  740.  
  741. /* Trace Raw Packing Vector */
  742.  
  743. static struct pvmtrcencvec pvmtrccodef_raw = {
  744.     tev_pack_byte_raw,
  745.     tev_pack_cplx_raw,
  746.     tev_pack_dcplx_raw,
  747.     tev_pack_double_raw,
  748.     tev_pack_float_raw,
  749.     tev_pack_int_raw,
  750.     tev_pack_uint_raw,
  751.     tev_pack_long_raw,
  752.     tev_pack_ulong_raw,
  753.     tev_pack_short_raw,
  754.     tev_pack_ushort_raw,
  755.     tev_pack_string_raw };
  756.  
  757.  
  758. /* Trace NOP Packing Vector */
  759.  
  760. static struct pvmtrcencvec pvmtrccodef_nop = {
  761.     tev_pack_nop,
  762.     tev_pack_nop,
  763.     tev_pack_nop,
  764.     tev_pack_nop,
  765.     tev_pack_nop,
  766.     tev_pack_nop,
  767.     tev_pack_nop,
  768.     tev_pack_nop,
  769.     tev_pack_nop,
  770.     tev_pack_nop,
  771.     tev_pack_nop,
  772.     tev_pack_nop };
  773.  
  774.  
  775. /*
  776.  *    tev_init()
  777.  *
  778.  *    Initialize Trace Status Vector.
  779.  */
  780.  
  781. void
  782. tev_init()
  783. {
  784.     int i;
  785.  
  786.     if ( pvmtrc.trctid > 0 && pvmmytid != pvmtrc.trctid )
  787.     {
  788.         /* Reset Trace Descriptor Counts */
  789.  
  790.         for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
  791.         {
  792.             pvmtevinfo[i].desc_status = 0;
  793.  
  794.             pvmtevinfo[i].mark.tv_sec =
  795.                 pvmtevinfo[i].mark.tv_usec = 0;
  796.  
  797.             pvmtevinfo[i].total.tv_sec =
  798.                 pvmtevinfo[i].total.tv_usec = 0;
  799.  
  800.             pvmtevinfo[i].count = 0;
  801.         }
  802.     }
  803. }
  804.  
  805.  
  806. /*
  807.  *    tev_begin()
  808.  *
  809.  *    Trace Event Begin - create message, pack header
  810.  */
  811.  
  812. int
  813. tev_begin( kind, entry_exit )
  814. int kind;
  815. int entry_exit;
  816. {
  817.     struct timeval timestamp;
  818.  
  819.     int newbuffer;
  820.     int tmp;
  821.  
  822.     /* Get Timestamp */
  823.  
  824.     if ( pvmtrc.trcopt != PvmTraceCount )
  825.         gettimeofday( ×tamp, (struct timezone *) 0 );
  826.  
  827.     switch ( pvmtrc.trcopt )
  828.     {
  829.         case PvmTraceFull:
  830.         {
  831.             /* Check for Descriptor Dump (one each, begin/end events) */
  832.  
  833.             if ( (pvmtevinfo[ kind - TEV_FIRST ].desc_status)++ < 2 )
  834.             {
  835.                 /* Set Trace Event Packing Vector */
  836.  
  837.                 pvmtrccodef = &pvmtrccodef_desc;
  838.  
  839.                 /* Set Descriptor Mode */
  840.  
  841.                 pvmtrcdesc = 1;
  842.             }
  843.  
  844.             /* Set Regular Trace Event Packing & Mode */
  845.  
  846.             else
  847.             {
  848.                 pvmtrccodef = &pvmtrccodef_raw;
  849.             
  850.                 pvmtrcdesc = 0;
  851.             }
  852.  
  853.             /* Initialize Trace Event Message Buffer? */
  854.  
  855.             newbuffer = 0;
  856.  
  857.             if ( !pvmtrcsbf )
  858.             {
  859.                 pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
  860.                 pvmtrcmp = midtobuf( pvmtrcsbf );
  861.  
  862.                 newbuffer++;
  863.             }
  864.  
  865.             /* Select Trace Event Buffer (save current) */
  866.  
  867.             pvmtrcsbfsave = pvm_setsbuf( pvmtrcsbf );
  868.  
  869.             /* Pack Event Buffer Marker */
  870.  
  871.             if ( newbuffer && pvmtrc.trcbuf )
  872.             {
  873.                 tmp = TEV_MARK_EVENT_BUFFER;
  874.                 pvm_pkint( &tmp, 1, 1 );
  875.             }
  876.  
  877.             /* Descriptor Header */
  878.  
  879.             if ( pvmtrcdesc )
  880.             {
  881.                 /* Pack Event Marker */
  882.  
  883.                 tmp = TEV_MARK_EVENT_DESC;
  884.                 pvm_pkint( &tmp, 1, 1 );
  885.  
  886.                 /* Pack Descriptor Event ID & Event Name */
  887.  
  888.                 tmp = kind | entry_exit;
  889.                 pvm_pkint( &tmp, 1, 1 );
  890.  
  891.                 pvm_pkstr( pvmtevinfo[ kind - TEV_FIRST ].name );
  892.             }
  893.  
  894.             /* Regular Header */
  895.  
  896.             else
  897.             {
  898.                 /* Pack Event Marker */
  899.  
  900.                 tmp = TEV_MARK_EVENT_RECORD;
  901.                 pvm_pkint( &tmp, 1, 1 );
  902.  
  903.                 /* Pack Event ID */
  904.  
  905.                 tmp = kind | entry_exit;
  906.                 pvm_pkint( &tmp, 1, 1 );
  907.             }
  908.  
  909.             /* Pack Event Header */
  910.  
  911.             TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
  912.                 (int *) &(timestamp.tv_sec), 1, 1 );
  913.             TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
  914.                 (int *) &(timestamp.tv_usec), 1, 1 );
  915.             TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
  916.                 &pvmmytid, 1, 1 );
  917.             
  918.             break;
  919.         }
  920.  
  921.         case PvmTraceTime:
  922.             pvmtrccodef = &pvmtrccodef_nop;
  923.             pvmtevinfo[ kind - TEV_FIRST ].mark = timestamp;
  924.             pvmtrcsavekind = kind;
  925.             break;
  926.  
  927.         case PvmTraceCount:
  928.             pvmtrccodef = &pvmtrccodef_nop;
  929.             pvmtrcsavekind = kind;
  930.             break;
  931.  
  932.         default:
  933.             pvmlogprintf(
  934.                 "Uh-Oh! Bogus Tracing Option (%d) in tev_begin()...\n",
  935.                 pvmtrc.trcopt );
  936.             pvmtrccodef = &pvmtrccodef_nop;
  937.             break;
  938.     }
  939.  
  940.     return( 1 );
  941. }
  942.  
  943.  
  944. /*
  945.  *    tev_fin()
  946.  *
  947.  *    Trace Event End - send message (check trace buffering)
  948.  */
  949.  
  950. int
  951. tev_fin()
  952. {
  953.     struct timeval timestamp;
  954.  
  955.     int flush;
  956.     int size;
  957.     int tmp;
  958.  
  959.     switch ( pvmtrc.trcopt )
  960.     {
  961.         case PvmTraceFull:
  962.         {
  963.             /* Pack End of Event Descriptor Marker */
  964.  
  965.             if ( pvmtrcdesc )
  966.             {
  967.                 tmp = TEV_MARK_EVENT_DESC_END;
  968.                 pvm_pkint( &tmp, 1, 1 );
  969.             }
  970.  
  971.             /* Pack End of Event Marker */
  972.  
  973.             else
  974.             {
  975.                 tmp = TEV_MARK_EVENT_RECORD_END;
  976.                 pvm_pkint( &tmp, 1, 1 );
  977.             }
  978.  
  979.             /* Check for Trace Message Send */
  980.             /* (pvmtrc.trcbuf == 0 means no buffering) */
  981.  
  982.             flush = 0;
  983.  
  984.             if ( !pvmtrc.trcbuf )
  985.                 flush++;
  986.  
  987.             else
  988.             {
  989.                 if ( pvm_bufinfo( pvmtrcsbf, &size,
  990.                         (int *) NULL, (int *) NULL ) ) {
  991.                     pvmlogerror(
  992.                         "tev_fin() error - get trace buffer size\n" );
  993.                     size = -1;
  994.                 }
  995.  
  996.                 if ( size >= pvmtrc.trcbuf )
  997.                     flush++;
  998.             }
  999.  
  1000.             if ( flush )
  1001.                 tev_flush( 0 );
  1002.     
  1003.             /* Reset Send Buffer */
  1004.  
  1005.             pvm_setsbuf( pvmtrcsbfsave );
  1006.             pvmtrcsbfsave = 0;
  1007.  
  1008.             break;
  1009.         }
  1010.  
  1011.         case PvmTraceTime:
  1012.             gettimeofday( ×tamp, (struct timezone *) 0 );
  1013.             TVXSUBY( &(pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].total),
  1014.                 ×tamp,
  1015.                 &(pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].mark) );
  1016.             (pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].count)++;
  1017.             break;
  1018.  
  1019.         case PvmTraceCount:
  1020.             (pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].count)++;
  1021.             break;
  1022.  
  1023.         default:
  1024.             pvmlogprintf(
  1025.                 "Uh-Oh! Bogus Tracing Option (%d) in tev_fin()...\n",
  1026.                 pvmtrc.trcopt );
  1027.             break;
  1028.     }
  1029.  
  1030.     return( 1 );
  1031. }
  1032.  
  1033.  
  1034. /*
  1035.  *    tev_flush( setflag )
  1036.  *
  1037.  *        setflag - indicates whether current send buffer is
  1038.  *            already the trace buffer (0), or whether it needs
  1039.  *            to be set (1).
  1040.  *
  1041.  *    Trace Event Flush - send message, flush any trace buffer
  1042.  */
  1043.  
  1044. void
  1045. tev_flush( setflag )
  1046. int setflag;
  1047. {
  1048.     char *event_names[ TEV_MAX - TEV_FIRST + 1 ];
  1049.  
  1050.     int timings_usec[ TEV_MAX - TEV_FIRST + 1 ];
  1051.     int timings_sec[ TEV_MAX - TEV_FIRST + 1 ];
  1052.     int counts[ TEV_MAX - TEV_FIRST + 1 ];
  1053.  
  1054.     struct timeval timestamp;
  1055.  
  1056.     int routetmp;
  1057.     int savebuf;
  1058.     int num;
  1059.     int tmp;
  1060.     int i;
  1061.  
  1062.     if ( pvmtrc.trctid <= 0 || pvmmytid == pvmtrc.trctid )
  1063.         return;
  1064.  
  1065.     switch ( pvmtrc.trcopt )
  1066.     {
  1067.         case PvmTraceFull:
  1068.         {
  1069.             if ( setflag )
  1070.             {
  1071.                 /* Verify Trace Record Message Buffer */
  1072.  
  1073.                 if ( !pvmtrcsbf )
  1074.                     return;
  1075.  
  1076.                 /* Set Send Buffer */
  1077.  
  1078.                 savebuf = pvm_setsbuf( pvmtrcsbf );
  1079.             }
  1080.  
  1081.             /* Pack End of Event Buffer Marker */
  1082.             /* (pvmtrcbuf == 0 means no buffering) */
  1083.  
  1084.             if ( pvmtrc.trcbuf )
  1085.             {
  1086.                 tmp = TEV_MARK_EVENT_BUFFER_END;
  1087.                 pvm_pkint( &tmp, 1, 1 );
  1088.             }
  1089.  
  1090.             break;
  1091.         }
  1092.  
  1093.         case PvmTraceTime:
  1094.         {
  1095.             /* Set Up Send Buffer */
  1096.  
  1097.             pvmtrccodef = &pvmtrccodef_desc;
  1098.  
  1099.             pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
  1100.             pvmtrcmp = midtobuf( pvmtrcsbf );
  1101.  
  1102.             savebuf = pvm_setsbuf( pvmtrcsbf );
  1103.  
  1104.             /* Pack Event Marker */
  1105.  
  1106.             tmp = TEV_MARK_EVENT_DESC;
  1107.             pvm_pkint( &tmp, 1, 1 );
  1108.  
  1109.             /* Pack Descriptor Event ID & Event Name */
  1110.  
  1111.             tmp = TEV_TIMING;
  1112.             pvm_pkint( &tmp, 1, 1 );
  1113.  
  1114.             pvm_pkstr( pvmtevinfo[ TEV_TIMING - TEV_FIRST ].name );
  1115.  
  1116.             /* Pack Event Header */
  1117.  
  1118.             gettimeofday( ×tamp, (struct timezone *) 0 );
  1119.  
  1120.             TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
  1121.                 (int *) &(timestamp.tv_sec), 1, 1 );
  1122.             TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
  1123.                 (int *) &(timestamp.tv_usec), 1, 1 );
  1124.             TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
  1125.                 &pvmmytid, 1, 1 );
  1126.  
  1127.             /* Collect Timing Array */
  1128.  
  1129.             num = 0;
  1130.  
  1131.             for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
  1132.             {
  1133.                 if ( pvmtevinfo[i].count > 0 )
  1134.                 {
  1135.                     event_names[num] = pvmtevinfo[i].name;
  1136.  
  1137.                     timings_sec[num] = pvmtevinfo[i].total.tv_sec;
  1138.                     timings_usec[num] = pvmtevinfo[i].total.tv_usec;
  1139.  
  1140.                     counts[num] = pvmtevinfo[i].count;
  1141.  
  1142.                     pvmtevinfo[i].total.tv_sec =
  1143.                         pvmtevinfo[i].total.tv_usec = 0;
  1144.  
  1145.                     pvmtevinfo[i].count = 0;
  1146.  
  1147.                     num++;
  1148.                 }
  1149.             }
  1150.  
  1151.             /* Pack Number of Events & Arrays */
  1152.  
  1153.             TEV_PACK_INT( TEV_DID_VCT, TEV_DATA_SCALAR,
  1154.                 &num, 1, 1 );
  1155.  
  1156.             TEV_PACK_STRING( TEV_DID_VID, TEV_DATA_ARRAY,
  1157.                 event_names, num, 1 );
  1158.  
  1159.             TEV_PACK_INT( TEV_DID_TGS, TEV_DATA_ARRAY,
  1160.                 timings_sec, num, 1 );
  1161.  
  1162.             TEV_PACK_INT( TEV_DID_TGU, TEV_DATA_ARRAY,
  1163.                 timings_usec, num, 1 );
  1164.  
  1165.             TEV_PACK_INT( TEV_DID_PRF, TEV_DATA_ARRAY,
  1166.                 counts, num, 1 );
  1167.  
  1168.             /* Pack End of Descriptor Marker */
  1169.  
  1170.             tmp = TEV_MARK_EVENT_DESC_END;
  1171.             pvm_pkint( &tmp, 1, 1 );
  1172.  
  1173.             setflag = 1;
  1174.  
  1175.             break;
  1176.         }
  1177.  
  1178.         case PvmTraceCount:
  1179.         {
  1180.             /* Set Up Send Buffer */
  1181.  
  1182.             pvmtrccodef = &pvmtrccodef_desc;
  1183.  
  1184.             pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
  1185.             pvmtrcmp = midtobuf( pvmtrcsbf );
  1186.  
  1187.             savebuf = pvm_setsbuf( pvmtrcsbf );
  1188.  
  1189.             /* Pack Event Marker */
  1190.  
  1191.             tmp = TEV_MARK_EVENT_DESC;
  1192.             pvm_pkint( &tmp, 1, 1 );
  1193.  
  1194.             /* Pack Descriptor Event ID & Event Name */
  1195.  
  1196.             tmp = TEV_PROFILING;
  1197.             pvm_pkint( &tmp, 1, 1 );
  1198.  
  1199.             pvm_pkstr( pvmtevinfo[ TEV_PROFILING - TEV_FIRST ].name );
  1200.  
  1201.             /* Pack Event Header */
  1202.  
  1203.             gettimeofday( ×tamp, (struct timezone *) 0 );
  1204.  
  1205.             TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
  1206.                 (int *) &(timestamp.tv_sec), 1, 1 );
  1207.             TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
  1208.                 (int *) &(timestamp.tv_usec), 1, 1 );
  1209.             TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
  1210.                 &pvmmytid, 1, 1 );
  1211.  
  1212.             /* Collect Profiling Array */
  1213.  
  1214.             num = 0;
  1215.  
  1216.             for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
  1217.             {
  1218.                 if ( pvmtevinfo[i].count > 0 )
  1219.                 {
  1220.                     event_names[num] = pvmtevinfo[i].name;
  1221.  
  1222.                     counts[num] = pvmtevinfo[i].count;
  1223.  
  1224.                     pvmtevinfo[i].count = 0;
  1225.  
  1226.                     num++;
  1227.                 }
  1228.             }
  1229.  
  1230.             /* Pack Number of Events & Arrays */
  1231.  
  1232.             TEV_PACK_INT( TEV_DID_VCT, TEV_DATA_SCALAR,
  1233.                 &num, 1, 1 );
  1234.  
  1235.             TEV_PACK_STRING( TEV_DID_VID, TEV_DATA_ARRAY,
  1236.                 event_names, num, 1 );
  1237.  
  1238.             TEV_PACK_INT( TEV_DID_PRF, TEV_DATA_ARRAY,
  1239.                 counts, num, 1 );
  1240.  
  1241.             /* Pack End of Descriptor Marker */
  1242.  
  1243.             tmp = TEV_MARK_EVENT_DESC_END;
  1244.             pvm_pkint( &tmp, 1, 1 );
  1245.  
  1246.             setflag = 1;
  1247.  
  1248.             break;
  1249.         }
  1250.  
  1251.         default:
  1252.             pvmlogprintf(
  1253.                 "Uh-Oh! Bogus Tracing Option (%d) in tev_flush()...\n",
  1254.                 pvmtrc.trcopt );
  1255.             return;
  1256.     }
  1257.  
  1258.     /* Send Message */
  1259.  
  1260.     if ( (routetmp = pvmrouteopt) == PvmRouteDirect )
  1261.         pvmrouteopt = PvmAllowDirect;
  1262.  
  1263.     pvmtrcmp->m_ctx = pvmtrc.trcctx;
  1264.  
  1265.     mroute( pvmtrcsbf, pvmtrc.trctid, pvmtrc.trctag, &pvmtrcztv );
  1266.  
  1267.     pvmrouteopt = routetmp;
  1268.  
  1269.     /* Clean-up */
  1270.  
  1271.     pvm_freebuf( pvmtrcsbf );
  1272.  
  1273.     pvmtrcsbf = 0;
  1274.  
  1275.     /* Reset Send Buffer */
  1276.  
  1277.     if ( setflag )
  1278.         pvm_setsbuf( savebuf );
  1279. }
  1280.  
  1281.  
  1282. /*
  1283.  *    tev_do_trace()
  1284.  *
  1285.  *    Export TEV_DO_TRACE() so user code doesn't have to import
  1286.  *    masks and trace tid, etc.
  1287.  */
  1288.  
  1289. int
  1290. tev_do_trace( kind, entry_exit )
  1291.     int kind;
  1292.     int entry_exit;
  1293. {
  1294.     TEV_DECLS
  1295.  
  1296.     return( TEV_DO_TRACE( kind, entry_exit ) );
  1297. }
  1298.  
  1299.  
  1300.